#include <iostream>
#include <string>
using namespace std;

// 类模版对象做函数参数

template<class T1, class T2>
class Person
{
public:
    T1 name;
    T2 age;

    Person(T1 name, T2 age)
    {
        this->name = name;
        this->age = age;
    }

    void show()
    {
        cout << "姓名：" << this->name << endl;
        cout << "年龄：" << this->age << endl;
    }

};

//1、指定传入参数
void printPerson1(Person<string, int>& p)
{
    p.show();
}

void test1()
{
    Person<string, int> p("孙悟空", 999);
    printPerson1(p);
}

//2、参数模版化
template<class T1,class T2>
void printPerson2(Person<T1, T2>& p)
{
    p.show();
    cout << "T1的类型为：" << typeid(T1).name() << endl;
    cout << "T2的类型为：" << typeid(T2).name() << endl;
    
}


void test2()
{
    Person<string, int> p("猪八戒", 1000);
    printPerson2(p);
}

//3、整个类模版化
template<class T>
void printPerson3(T& p)
{
    p.show();
    cout << "T的数据类型为：" << typeid(T).name() << endl;
}

void test3()
{
    Person<string, int>p("唐僧", 30);
    printPerson3(p);
}


int main()
{
    test1();
    cout << "---------------------" << endl;
    test2();
    cout << "---------------------" << endl;
    test3();
    return 0;
}